package com.sip.dbadapter.dao.domain;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

/**
 *
 */
@Entity
@Table(name = "PRODUCE_TYPE")
public class ProduceType implements Serializable {

	private static final long serialVersionUID = 1L;

	private Long producerId ;

	private String grammerDefinition;

	private Integer type;

	private ApiDefinition apiDefinitionProduceType;

	public ProduceType() {
		producerId= Long.valueOf(0);
	}

	@Id
	@Column(name = "PRODUCE_ID", unique = true, nullable = false)
	@GeneratedValue
	public Long getProducerId() {

		return producerId;
	}

	@Column(name = "GRAMMER_DEFINITION", nullable = false)
	public String getGrammerDefinition() {

		return grammerDefinition;
	}

	@Column(name = "TYPE", nullable = false)
	public Integer getType() {

		return type;
	}
	

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "API_ID", nullable = true)
	public ApiDefinition getApiDefinitionProduceType() {
		return apiDefinitionProduceType;
	}


	public void setProducerId(Long producerId) {

		this.producerId = producerId;
	}

	public void setGrammerDefinition(String grammerDefinition) {

		this.grammerDefinition = grammerDefinition;
	}

	public void setType(Integer type) {

		this.type = type;
	}

	public void setApiDefinitionProduceType(ApiDefinition apiDefinitionProduceType) {
		this.apiDefinitionProduceType = apiDefinitionProduceType;
	}

	@Override
	public int hashCode() {

		int result = 0;
		result = (int) (31 * result + producerId);
		result = 31 * result + (grammerDefinition != null ? grammerDefinition.hashCode() : 0);
		result = 31 * result + (type != null ? type.hashCode() : 0);

		return result;
	}

	@Override
	public boolean equals(Object other) {

		if (this == other)
			return true;

		if (other == null || (this.getClass() != other.getClass())) {
			return false;
		}

		ProduceType producerType = (ProduceType) other;
		return (this.producerId == producerType.producerId)
				&& (this.grammerDefinition != null && grammerDefinition.equals(producerType.grammerDefinition))
				&& (this.type != null && type.equals(producerType.type));
	}

}
